package com.hr.service.impl;

import com.hr.service.AiFunctionService;
import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
@AllArgsConstructor
public class AiFunctionServiceImpl implements AiFunctionService {

   private final RedisTemplate<String, Object> redisTemplate;
    /**
     * 获取会话列表
     * @param userId 用户ID
     * @return 会话列表
     */
    @Override
    public List<String> getConversationList(String userId) {
        // 获取所有以"chat_memory:user:"开头的键
        Set<String> keys = redisTemplate.keys("chat_memory:user:" + userId + ":chatId:*");
        List<String> collect = keys.stream()
                .map(key -> key.split(":")[4])
                .collect(Collectors.toList());
        return collect;


    }
}
